package com.gable.report.controller;

import com.gable.report.common.util.ReturnResultUtil;
import com.gable.report.model.ChartsAreaQuery;
import com.gable.report.model.User;
import com.gable.report.service.ChartsForAreaMaintenanceService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 区维护报表
 * Created by mj on 2017/7/26.
 */
@Controller
@RequestMapping(value = "charts/area/maintenance")
public class ChartsForAreaMaintenanceController {
    private final Log logger = LogFactory.getLog(this.getClass());

    @Autowired
    ChartsForAreaMaintenanceService maintenanceService;

    @Autowired
    HttpServletRequest request;

    //医院维护报表跳转页面
    @RequestMapping("/hospital-page")
    public String pageHospital(){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return "charts-authority";
        }
        return "charts/area/maintenance-hospital";
    }

    //医院维护报表
    @RequestMapping(value ="/hospital" ,method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryHospitalAssetsForMaintenance(ChartsAreaQuery chartsAreaQuery, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryHospitalAssetsForMaintenance(user,chartsAreaQuery);
    }

    //产品类型维护报表跳转页面
    @RequestMapping("/type-page")
    public String pageType(){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return "charts-authority";
        }
        return "charts/area/maintenance-type";
    }

    //产品类型维护报表
    @RequestMapping(value ="/type" ,method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryDeviceTypeSubAssetsForMaintenance(ChartsAreaQuery chartsAreaQuery, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryDeviceTypeSubAssetsForMaintenance(user,chartsAreaQuery);
    }


    //厂家维护报表
    @RequestMapping(value ="/brand" ,method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryManufactureAssetsForMaintenance(ChartsAreaQuery chartsAreaQuery, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryManufactureAssetsForMaintenance(user,chartsAreaQuery);
    }

    //设备型号报表跳转页面
    @RequestMapping("/model-page")
    public String pageModel(){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return "charts-authority";
        }
        return "charts/area/maintenance-model";
    }

    //设备型号维护报表
    @RequestMapping(value ="/model" ,method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryModelAssetsForMaintenance(ChartsAreaQuery chartsAreaQuery, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryModelAssetsForMaintenance(user,chartsAreaQuery);
    }

    /**
     * @Description:  设备绩效
     * @param chartsAreaQuery
     * @return
     */
    @RequestMapping(value="/assets",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryAssets(ChartsAreaQuery chartsAreaQuery){
        User user = (User)request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryAssets(user,chartsAreaQuery);
    }

    /**
     * @Description:  维护概况
     * @param chartsAreaQuery
     * @return
     */
    @RequestMapping(value="/overview-hospital",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryOverview(ChartsAreaQuery chartsAreaQuery){
        User user = (User)request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryOverview(user,chartsAreaQuery);
    }

    /**
     * @Description:  月份维护报表
     * @param chartsAreaQuery
     * @return
     */
    @RequestMapping(value="/month-trend",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryForMonth(ChartsAreaQuery chartsAreaQuery){
        User user = (User)request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryForMonth(user,chartsAreaQuery);
    }

    /**
     * @Author: 杨青桦
     * @Description: 实际维护记录详情
     * @Date: 2018/7/9 14:37
     * @param chartsAreaQuery
     * @param request
     * @return
     */
    @RequestMapping(value="/actual/record",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryActualRecords(ChartsAreaQuery chartsAreaQuery, HttpServletRequest request){
        User user = (User)request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryActualRecords(user,chartsAreaQuery);
    }

    /**
     * @Author: 杨青桦
     * @Description: 计划维护记录详情
     * @Date: 2018/7/9 14:37
     * @param chartsAreaQuery
     * @param request
     * @return
     */
    @RequestMapping(value="/plan/record",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryPlanRecords(ChartsAreaQuery chartsAreaQuery, HttpServletRequest request){
        User user = (User)request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryPlanRecords(user,chartsAreaQuery);
    }

    /**
     * @Author: 杨青桦
     * @Description: 实际维护设备资产信息
     * @Date: 2018/7/9 14:37
     * @param chartsAreaQuery
     * @param request
     * @return
     */
    @RequestMapping(value="/actual/assets",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryActualAssets(ChartsAreaQuery chartsAreaQuery, HttpServletRequest request){
        User user = (User)request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryActualAssets(user,chartsAreaQuery);
    }

    /**
     * @Author: 杨青桦
     * @Description: 计划维护设备资产信息
     * @Date: 2018/7/9 14:37
     * @param chartsAreaQuery
     * @param request
     * @return
     */
    @RequestMapping(value="/plan/assets",method= RequestMethod.POST,produces="application/json;charset=utf-8")
    @ResponseBody
    public ReturnResultUtil queryPlanAssets(ChartsAreaQuery chartsAreaQuery, HttpServletRequest request){
        User user = (User)request.getSession().getAttribute("loginUser");
        if(user.getGovernmentType() == null){
            return new ReturnResultUtil(0,"该用户不存在");
        }
        return maintenanceService.queryPlanAssets(user,chartsAreaQuery);
    }
}
